//package com.itcast.activiti.listener;
//
//import com.alibaba.fastjson.JSONObject;
//import com.itcast.msas.sdk.msg.api.WechatMsgApi;
//import com.itcast.msas.sdk.msg.domain.WechatTxtMsgDto;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
//import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
//import org.apache.rocketmq.common.protocol.heartbeat.MessageModel;
//import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
//import org.apache.rocketmq.spring.core.RocketMQListener;
//import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//import org.springframework.util.StringUtils;
//
//import java.util.List;
//
//@Slf4j
//@Component
//@RocketMQMessageListener(
//        topic = "${activiti.rocketmq.topic.activiti}",
//        consumerGroup = "${activiti.rocketmq.consumer.group.task_remind}",
//        selectorExpression = "TAG_ACTIVITI_TASK_REMIND")
//public class EnterpriseWeChatMessageQueueListener implements RocketMQListener<JSONObject>, RocketMQPushConsumerLifecycleListener {
//    @Autowired
//    private WechatMsgApi wechatMsgApi;
//    @Value("${enterprise.message.switch}")
//    private boolean messageSwitch;
//
//    @Override
//    public void onMessage(JSONObject message) {
//        if (!messageSwitch) {
//            return;
//        }
//        log.info("EnterpriseWeChatMessageQueueListener {}", message);
//        List<String> accounts = (List<String>) message.get("accounts");
//        String content = message.getString("content");
//        if (accounts == null || accounts.size() == 0 || !StringUtils.hasText(content)) {
//            return;
//        }
//        WechatTxtMsgDto wechatTxtMsgDto = new WechatTxtMsgDto();
//        wechatTxtMsgDto.setAccounts(accounts);
//        wechatTxtMsgDto.setContent(content);
//        wechatMsgApi.sendTextMsg(wechatTxtMsgDto);
//    }
//
//    @Override
//    public void prepareStart(DefaultMQPushConsumer defaultMQPushConsumer) {
//        defaultMQPushConsumer.setConsumeTimeout(1);
//        defaultMQPushConsumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
//        defaultMQPushConsumer.setMaxReconsumeTimes(3);
//        defaultMQPushConsumer.setMessageModel(MessageModel.CLUSTERING);
//    }
//}